package tw.com.com;



import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

//import org.apache.log4j.Logger;

import tw.com.bean.DTO;
import tw.com.bean.Stock;

public class TxtOut implements MyWriter {

//	final Logger logger = Logger.getLogger(TxtOut.class);

	@Override
	public void outPut(DTO dto) throws Exception {

//		logger.debug("TxtOut outPut start!");

		BufferedWriter wStream = null;
		List<Stock> userData = dto.getStocks();
		String name = userData.get(0).getDate().getYyy() + ".txt";
		try {

			wStream = new BufferedWriter(new FileWriter(name));
			String tempYyy = null;

			for (Stock aStock : userData) {

				new BufferedWriter(new FileWriter(name));

				if (tempYyy == null) {
					tempYyy = aStock.getDate().getYyy();
				}

				wStream.write(aStock.getDate().getYyy()
						+ aStock.getDate().getMm() + aStock.getDate().getDd()
						+ "\t" + aStock.getSockVal());

				wStream.newLine();
  
				// tempYyy=aStock.getDate().getYyy();

			}
			wStream.flush();

		} catch (IOException e) {		
			e.printStackTrace();
		} finally {
			try {
				wStream.close();
			} catch (IOException e) {				
				e.printStackTrace();
			}
		}
//		logger.debug("TxtOut outPut end!");

	}

}
